package com.blu.blutemperaturecontrol.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.blu.blutemperaturecontrol.content.StaticVariable;
import com.google.gson.Gson;
import com.jaeger.library.StatusBarUtil;

import butterknife.ButterKnife;

/**
 * Created by mac on 27/4/16.
 * BaseActivity
 */
public abstract class BaseActivity extends AppCompatActivity {

    public Gson gson;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        int currentapiVersion = android.os.Build.VERSION.SDK_INT;
        if(isShowStatusBar() && currentapiVersion>19){//当安卓版本大于4.4才能改变状态栏颜色
            //设置状态栏颜色
            StatusBarUtil.setColor(this,0xFFff0000,0);
        }
        //把创建的activity都存到集合中   退出系统的时候全部关闭
        StaticVariable.addActivity(this);

        // 绑定视图和事件
        ButterKnife.bind(this);

        gson = new Gson();

        // 初始化视图，子类实现
        this.initViews();

        // 加载数据，子类实现
        this.loadData();

    }

    /**
     * 销毁Activity
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        StaticVariable.getActivityList().remove(this);
    }


    //设置状态栏颜色
    protected boolean isShowStatusBar(){
        return true;
    }

    // 获取布局，子类实现逻辑
    protected abstract int getLayoutId();



    // 初始化视图，此方法调用前，视图已经初始化
    protected abstract void initViews();

    // 加载所需数据，子类实现逻辑
    protected abstract void loadData();

}
